iT邦幫忙

2024 iThome 鐵人賽

DAY 5
0
生成式 AI

T 大使 AI 之旅系列 第 5

【Day 05】Ollama UI 圖片生成

  • 分享至 

  • xImage
  •  

前情提要

上一篇文章使用了 Open WebUI 介面的 RAG 功能還有修改 Prompt,可以上傳檔案,然後詢問 AI 檔案中的相關問題。那今天就來繼續使用 Open WebUI 來生成圖片。

https://ithelp.ithome.com.tw/upload/images/20240810/20168336mI5weEa8l3.png

圖片生成

今天先用上面的圖來開頭,這算是我的夢想辦公環境了吧。空間大、辦公桌也大,然後還有太陽照進來和綠色植物,然後做著我最喜歡的 code 的工作,感覺會是很舒服的辦公空間。後面黑板的文字呼應這次的 IT 鐵人賽生成式 AI 主題,然後下面的模型微調 (Model Fine-Tune)、檢索增強生成 (RAG)、呼叫 API 都是我這次實作會使用到的技術。接下來就讓我來分享我生成圖片的這些生成式 AI 工具吧!

Stable Diffusion

Stable Diffusion 應該算是蠻多人都聽過的開源免費模型,因為他僅用消費級的 GPU 就可以繪出圖片,爬文時看到 Colab 現在偵測到是 Stable Diffusion 的話會要求要使用付費版才可以使用。那他背後很複雜的模型和架構還有他無聊的發展史我就不贅述了,開始著手安裝到本機吧!

  1. 來到他的 GitHub,我不確定他跟 Open WebUI 有沒有什麼的關係,但是可以整個串起來用。跟之前下載 Open WebUI 一樣,透過 git 語法抓下整包檔案,就可以在資料夾中找到 stable-diffusion-webui 這個資料夾。
  2. Stable Diffusion 是基於 Pytorch 架構,所以一樣為他開設一個 conda 虛擬環境,並且使用指令安裝他的依賴套件。
  3. 完成 Stable Diffusion 環境,接著透過指令就可以使用了!

這個指令開啟之後可以看到 Stable Diffusion 的 UI 介面。

sh webui.sh

https://ithelp.ithome.com.tw/upload/images/20240809/20168336k0nxHTK7rG.png

但是去 Open WebUI -> Settings -> images 頁面會提示無法連線,所以要更改啟動 Stable Diffusion 的指令。
https://ithelp.ithome.com.tw/upload/images/20240809/20168336SOKbwlBjH0.png

在指令最後加上 "api",回到 images 頁面,就會顯示連線成功,然後 Image Generation 要打開,這樣就可以將 ollama 與 stable diffusion 透過 Open WebUI來產生圖片啦!

sh webui.sh --api

https://ithelp.ithome.com.tw/upload/images/20240809/20168336a7KmatLnBn.png

實戰🔥

簡單輸入一個圖片的敘述,AI 會先回答一段東西,但那個都不是重點。重點是等他文字生成完之後,要按下最下面生成圖片的圖示,就會開始根據指令產出圖片了!
https://ithelp.ithome.com.tw/upload/images/20240809/20168336lVY6XLot2W.png

CIVIT AI

Civitai 這個網站有各種別人訓練好的圖片生成開源模型,像是動漫類、動物類、人像等等。我自己看下來還是虛擬畫風偏多,但我本身沒在接觸動漫,所以就沒深入研究這個種類的模型。

實戰🔥

我自己還是挑了兩個模型跟大家分享:

  • WildCompanion 這個模型的專長看起來是生成很逼真的動物,像上面那張圖的老鷹就是這個模型生成的,其實我自己是覺得蠻逼真的啦,不會說真的很 AI。以下兩個北極熊🐻‍❄️和松鼠🐿️我自己看起來很像真的動物,而不是動畫那種的。
    https://ithelp.ithome.com.tw/upload/images/20240809/20168336HKGKB6fYM5.pnghttps://ithelp.ithome.com.tw/upload/images/20240809/201683369wHhHJd1iL.png

  • Daiquiri Photoreal 這個模型是生成人像的,從網站展示的資料看起來是擅長生成亞洲人。會挑選這個是我自己覺得他生成的人像算很像真人了,相對於 civitai 上的其他 Realphoto Model。但我自己用下來,不知道是 llama3.1 Model 的問題,或者是 Open WebUI 的問題。生成的人像就沒有很逼真,雖然是已經很強了。 (或者有大神可以建議我 prompt 怎麼下比較好)
    https://ithelp.ithome.com.tw/upload/images/20240809/20168336QFjOl7OIRM.pnghttps://ithelp.ithome.com.tw/upload/images/20240809/201683365J4w0RhtFp.png

番外篇

同樣是這個 Daiquiri Photoreal Model,我後來想說在 Stable Diffusion 的 UI 介面玩玩看。結果發現這個模型「尺度很大」,但礙於 🔞 的關係沒辦法放實例出來,真的會讓人噴鼻血。有興趣的人可以自己去試試玩玩,我這邊一樣分享幾個實戰成果給大家看看!
https://ithelp.ithome.com.tw/upload/images/20240809/20168336E8xeNZOL6T.jpg

Midjourney

最後來看看 Midjourney,我必須說只要 Prompt 對了,基本上他可以非常高機率的達到你所想像的樣子。我頁首的那張辦公室圖片就是使用 Midjourney 生成的,他精準到 Prompt 跟他說在哪寫什麼字都可以做到,真的很🐮🍺。這邊分享一下我生成頁首的那張辦公室圖的 Prompt,也歡迎大家留言跟我討論分享有什麼好用的 Prompt。

Imagine a modern high-tech workspace located in a stylish office environment. On the left side of the image, there are two young professionals, a man and a woman, holding coffee cups while discussing the code displayed on the monitor at their desk. In front of them is a large black office desk equipped with multiple high-resolution monitors, each showing lines of code in a dark-themed editor. The person is fully focused, typing on a mechanical keyboard, surrounded by equipment that suggests they are engaged in advanced programming or data modeling work.

On the wall behind the desk, the words "iThome GenAI" are prominently displayed in a bold, futuristic font. Surrounding it are hand-drawn charts, flow diagrams, and technical terms related to "Model Fine-Tune," "LLMs," "RAG," and "API." These visual elements are composed of hexagonal designs, arrows, and text, giving the impression of ongoing brainstorming or project planning. On the right side of the scene, a large whiteboard is filled with additional sketches, diagrams, and notes, further reinforcing the dynamic, creative problem-solving atmosphere.

The workspace is well-lit with clean, modern lines, and a few indoor plants add a touch of greenery. In the foreground, there are several books related to "AI." The overall ambiance is vibrant, full of innovation and focus, showcasing a cutting-edge work environment in a high-tech setting.

額外分享:玩一整天 Midjourney 的結果

這些貓貓也太可愛😻
https://ithelp.ithome.com.tw/upload/images/20240809/20168336XW9g4GrQGD.png

這樣模特兒會失業吧...
https://ithelp.ithome.com.tw/upload/images/20240809/20168336YSj0XrfpGM.png
https://ithelp.ithome.com.tw/upload/images/20240809/20168336Yh6q7KN1Jo.png

結論

圖片生成真的是一個很酷的領域,不知道大家覺得這些圖片有沒有像真人呢?然後如果 Prompt 不知道該從何下手的人,找一張你喜歡的圖片問問 Chatgpt,就會有概念怎麼下了,因為我就是靠他給我 Prompt 的靈感和方向。另外如果有圖片生成的需求的話,不妨試試 Midjourney,我覺得就像 Colab 的 GPU 一樣的值得,希望未來可以自己訓練出一個我喜歡的圖片生成模型!

題外話🤣

換了 MacBook Pro 大概三個月了,這次圖片生成和 ollama 都是用內建的 GPU,看到 GPU 使用率拉滿真的覺得很爽。而且 MacOS 的使用體驗真的好好,真的用習慣就很舒服。但必須說最近接觸到一個 C# 的專案,使用 Mac 開發就很不方便,.NET 環境和 C# 還好解決,但就是 Windows 好像都用 Visual Studio (我之前都叫他紫色的 VS Code🤣)。這個 IDE 不支援 MacOS,在 co-work 上真的很頭痛,不知道有沒有用 Mac 開發 C# 專案的可以跟我分享。目前是拿我六年前買的電腦來做這個專案,但我總覺得他總有一天會不行,畢竟當初買這台電腦根本沒想過會來寫程式。

下一篇文章:Hugging Face 入門指南


上一篇
【Day 04】Ollama UI 應用
下一篇
【Day 06】Hugging Face 入門指南
系列文
T 大使 AI 之旅30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言